<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>换肤</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            background: url(./images/1.jpg) no-repeat center top;
        }
        
        li {
            list-style: none;
        }
        
        .change {
            overflow: hidden;
            margin: 100px auto;
            background-color: #fff;
            width: 410px;
            padding-top: 3px;
        }
        
        .change li {
            float: left;
            margin: 0 1px;
            cursor: pointer;
        }
        
        .change img {
            width: 100px;
        }
    </style>
</head>

<body>
    <ul class="change">
        <li><img src="./images/1.jpg" alt=""></li>
        <li><img src="./images/2.jpg" alt=""></li>
        <li><img src="./images/3.jpg" alt=""></li>
        <li><img src="./images/4.jpg" alt=""></li>
    </ul>
</body>
<script>
    //点了那张图片就换成那个背景
    //严谨的选择
    let imgs = document.querySelector('.change').querySelectorAll('img');
    // console.log(imgs);
    for (let i = 0; i < imgs.length; i++) {
        imgs[i].onclick = function() {
            console.log(this.src);
            //把这个路径给body
            document.body.style.backgroundImage = `url(${this.src})`
        }
    }
</script>

</html>